﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;

public partial class product_insurance_admin_claim_documents : System.Web.UI.Page
{
  

    protected void Page_Load(object sender, EventArgs e)
    {
        
          ClaimBLL bll = new ClaimBLL();

        String staffID = Session["userId"] as String;
        int insuredID = int.Parse(Request.QueryString["certificateNo"]);
        String caseId = Request.QueryString["caseId"];
        
        Hashtable claimDocs = bll.getClaimInfo(insuredID);
        this.lbDoc1_type.Text = claimDocs["docCategory1"] as String;
        this.lbDoc2_type.Text = claimDocs["docCategory2"] as String;
        this.lbDoc3_type.Text = claimDocs["docCategory3"] as String;
        this.lbDoc4_type.Text = claimDocs["docCategory4"] as String;
        this.lbDoc5_type.Text = claimDocs["docCategory5"] as String;
        this.lbDoc6_type.Text = claimDocs["docCategory6"] as String;

        String docPath1 = claimDocs["docPath1"] as String;
        String docPath2 = claimDocs["docPath2"] as String;
        String docPath3 = claimDocs["docPath3"] as String;
        String docPath4 = claimDocs["docPath4"] as String;
        String docPath5 = claimDocs["docPath5"] as String;
        String docPath6 = claimDocs["docPath6"] as String;
        
        this.link_view1.NavigateUrl = claimDocs["docPath1"] as String;
        this.link_view2.NavigateUrl = claimDocs["docPath2"] as String;
        this.link_view3.NavigateUrl = claimDocs["docPath3"] as String;
        this.link_view4.NavigateUrl = claimDocs["docPath4"] as String;
        this.link_view5.NavigateUrl = claimDocs["docPath5"] as String;
        this.link_view6.NavigateUrl = claimDocs["docPath6"] as String;

        this.hd_planType.Value = claimDocs["planType"] as String;
        this.hd_caseId.Value = caseId;
        this.hd_insuredId.Value = insuredID.ToString();

        if (!"".Equals(docPath1))
        {
            this.lbDoc1_type.Visible = true;
            this.link_view1.Visible = true;
        }
        else
        {
            this.lbDoc1_type.Visible = false;
            this.link_view1.Visible = false;
        }


        if (!"".Equals(docPath2))
        {

            this.lbDoc2_type.Visible = true;
            this.link_view2.Visible = true;
        }
        else
        {
            this.lbDoc2_type.Visible = false;
            this.link_view2.Visible = false;
        }


        if (!"".Equals(docPath3))
        {

            this.lbDoc3_type.Visible = true;
            this.link_view3.Visible = true;
        }
        else
        {
            this.lbDoc3_type.Visible = false;
            this.link_view3.Visible = false;
        }


        if (!"".Equals(docPath4))
        {

            this.lbDoc4_type.Visible = true;
            this.link_view4.Visible = true;
        }
        else
        {
            this.lbDoc4_type.Visible = false;
            this.link_view4.Visible = false;
        }


        if (!"".Equals(docPath5))
        {

            this.lbDoc5_type.Visible = true;
            this.link_view5.Visible = true;
        }
        else
        {
            this.lbDoc5_type.Visible = false;
            this.link_view5.Visible = false;
        }


        if (!"".Equals(docPath6))
        {

            this.lbDoc6_type.Visible = true;
            this.link_view6.Visible = true;
        }
        else
        {
            this.lbDoc6_type.Visible = false;
            this.link_view6.Visible = false;
        }

    }



    protected void btnconfirmed_Click(object sender, EventArgs e)
    {
        ClaimBLL bll = new ClaimBLL();
        try
        {
            bll.confirm(this.hd_planType.Value, int.Parse(this.hd_insuredId.Value), int.Parse(this.hd_caseId.Value), decimal.Parse(this.tbamount.Text), (String)Session["userId"], this.tbComment.Text);
            this.Response.Redirect("~/product/insurance/admin/insurance_claim_list.aspx");




        }
        catch(Exception ex)
        {
            if ("Over-Limit".Equals(ex.Message))
            {
                this.lbMessage.Text = "Claim Amount overlimit, should denied the claim!";
            }
            else
            {
                throw ex;

            }

        }
        
           // String planType,String insurance, String caseId, decimal amount, String staffID, String claimDescription
    }
    protected void btndenied_Click(object sender, EventArgs e)
    {
        if (this.tbComment.Text.Equals("") || this.tbComment.Text == null)
        {
            this.lbMessage.Text = "Please enter DENIED REASON!";


        }
        else
        {

            ClaimBLL bll = new ClaimBLL();
            bll.denied(this.hd_planType.Value, int.Parse(this.hd_insuredId.Value), int.Parse(this.hd_caseId.Value), 0, (String)Session["userId"], this.tbComment.Text);

        }
        this.Response.Redirect("~/product/insurance/admin/insurance_claim_list.aspx");
        

    }
}